<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2016/3/8
  Time: 13:42
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>修改角色</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1">
    <meta name="renderer" content="webkit">
    <link href="${pageContext.request.contextPath}/static/css/common.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/static/plugins/bootstrap-3.3.5/css/bootstrap.min.css"
          rel="stylesheet">
    <link href="${pageContext.request.contextPath}/static/plugins/font-awesome-4.3.0/css/font-awesome.min.css"
          rel="stylesheet">
    <link rel="stylesheet"
          href="${pageContext.request.contextPath}/static/plugins/zTree_v3-3.5.22/css/zTreeStyle/zTreeStyle.css"
          type="text/css">
    <script src="${pageContext.request.contextPath}/static/js/jquery-1.11.3.min.js"></script>
    <script src="${pageContext.request.contextPath}/static/plugins/bootstrap-3.3.5/js/bootstrap.min.js"></script>
    <script type="text/javascript"
            src="${pageContext.request.contextPath}/static/plugins/zTree_v3-3.5.22/js/jquery.ztree.core.js"></script>
    <script type="text/javascript"
            src="${pageContext.request.contextPath}/static/plugins/zTree_v3-3.5.22/js/jquery.ztree.excheck.js"></script>
	<style>
		.lt{float:left;}
		.form-group{*+overflow:hidden;}
		.form-group label{width:31%\9;*+width:14%;text-align:right\9;*+text-align:right;}
		.form-group .col-sm-8{width:66%\9;*+width:66%;}
		.col-sm-6{
			width:46%\9;
			*+width:46%;
			float:left;
		}
		select{*+border:none;}
		.box{*+height:20px;*+width:89%;}
	</style>
</head>
<body>
<div class="col-sm-12">
    <form class="form-horizontal m-t" id="form" method="post"
          action="${pageContext.request.contextPath}/admin/role_update.action">

        <input type="hidden" name="sid" value="${role.sid}"/>
        <div class="col-sm-6">
            <div class="form-group">
                <label class="col-sm-3  control-label lt"><i class="require">*</i>角色名:</label>
                <div class="col-sm-8 lt">
                    <input class="form-control box" name="rName" size="30" value="${role.rName}"/>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3  control-label lt"><i class="require">*</i>层级:</label>
	            <div class="col-sm-8 lt">
	                <select name="rLevel" id="rLevel" class="form-control">
	                <c:if test="${userRole == 1}">
	                    <option value="0">平台</option>
	                    <option value="1">公司</option>
	                    <option value="2">社区</option>
	                    <option value="3">锁厂</option>
	                </c:if>
	                <c:if test="${userRole == 2}">
	                    <option value="0">平台</option>
	                </c:if>
	                <c:if test="${userRole == 3}">
		                <c:if test="${rLevel == 1}">
		                	<c:if test="${role.isAdmin == 1 }">
		                		<option value="2">社区</option>
		                	</c:if>
		                	<c:if test="${role.isAdmin != 1 }">
			                    <option value="1">公司</option>
			                    <option value="2">社区</option>
		                	</c:if>
		                </c:if>
		                <c:if test="${rLevel == 3}">
		                    <option value="3">锁厂</option>
		                </c:if>
	                </c:if>
	                <c:if test="${userRole == 4}">
	                	<c:if test="${rLevel == 1}">
		                    <option value="1">公司</option>
		                </c:if>
		                <c:if test="${rLevel == 3}">
		                    <option value="3">锁厂</option>
		                </c:if>
	                </c:if>
	                <c:if test="${userRole == 5 or userRole == 6}">
	                    <option value="2">社区</option>
	                </c:if>
	                </select>
	            </div>
            </div>
            <div class="form-group">
               <label class="col-sm-3  control-label lt"><i class="require">*</i>状态:</label>
            <div class="col-sm-8 lt">
                <select name="status" id="status"  class="form-control">
                    <option value="1">激活</option>
                    <option value="0">禁止</option>
                </select>
            </div>
        </div>
        </div>
        <div class="col-sm-6">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h3 class="panel-title">权限设置</h3>
                </div>
                <div class="panel-body">
                    <input type="hidden" name="mList" id="mList">
                    <div class="col-sm-8">
                        <ul id="auths" class="ztree"></ul>
                    </div>
                </div>
            </div>
        </div>
    </form>
</div>
<script type="text/javascript">

    var ztree;
    var znodes;

    var setting = {
        check: {
            enable: true
        },
        data: {
            simpleData: {
                enable: true
            }
        }, callback: {
            onCheck: check
        }
    };

    setting.check.chkboxType = { "Y" : "p", "N" : "s" };

    $(document).ready(function () {
        var mList = "${role.mList}";
        var array = mList.split("|");
        $.post("/admin/auth_tree.action?sid="+'${role.sid}'+"&mType="+'${role.isAdmin}', function (result) {
            znodes = result;
            ztree = $.fn.zTree.init($("#auths"), setting, znodes);
            ztree.expandAll(true);
            for (var i = 0; i < znodes.length; i++) {
                var node = znodes[i].id;
                if (contains(array, node)) {
                    var node_obj = ztree.getNodeByParam("id", node, null);
                    ztree.checkNode(node_obj, true);
                }
            }
            check();
        }, "json");
    });
    
    

    function check() {
        var checks = new Array();
        var nodes = ztree.getCheckedNodes(true);
        for (var i in nodes) {
            checks.push(nodes[i].id);
        }
        $("#mList").val(checks.toString().replace(/,/g,"|"));
    }
    
    function contains(arr, obj) {
        var i = arr.length;
        while (i--) {
            if (arr[i] == obj) {
                return true;
            }
        }
        return false;
    }
    
    $(function(){
        $("#rLevel").val('${role.rLevel}');
        $("#status").val('${role.status}');
    });
</script>
</body>
</html>
